package com.fenghuajueli.module_find_the_difference.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.fenghuajueli.module_find_the_difference.R;

public class ZhaoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private int allCount = 0;
    private int currentCount = 0;

    public ZhaoAdapter(@NonNull Context context) {
        this.context = context;
    }

    public void addCurrentCount() {
        currentCount++;
        notifyDataSetChanged();
    }

    public void setAllCount(int allCount) {
        currentCount = 0;
        this.allCount = allCount;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_zhao, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder h = (ViewHolder) holder;

        if (position <= currentCount - 1) {
            h.ivImage.setImageResource(R.mipmap.aa_dadui);
        } else {
            h.ivImage.setImageResource(R.mipmap.aa_weidadui);
        }

    }

    @Override
    public int getItemCount() {
        return allCount;
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView ivImage;

        ViewHolder(View view) {
            super(view);
            ivImage = view.findViewById(R.id.iv_image);
        }
    }
}
